

class UserBasedExceptionMiddleware(object):
    '''
    from http://www.djangosnippets.org/snippets/935/
    Step 1 Save somewhere in your project directory

    Step 2 Add to your settings.py

    MIDDLEWARE_CLASSES = (
      'django.middleware.common.CommonMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.middleware.doc.XViewMiddleware',
      'utils.debug.UserBasedExceptionMiddleware',
    )

    Normal users will get your 500.html when debug = False,
    but If you are logged in as a super user then you get to see the stack trace in all its glory.
    '''

    def process_exception(self, request, exception):
        if request.user.is_superuser:
            from django.views.debug import technical_500_response
            import sys
            return technical_500_response(request, *sys.exc_info())
